/**
 * 
 */
package io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;

/**
 * @author Remi REBILLARD
 *
 */
public class ImportTableMovement {
	private BufferedReader buffer;
	
	private String header;
	private String[] top;
	private String[] row;
	
	/**
	 * @param inputstream
	 */
	public ImportTableMovement( InputStream is ){
		this.buffer = new BufferedReader( new InputStreamReader( is ) );
	}
	
	/**
	 * @return the data of file for TableMovement
	 */
	public HashMap< String, Integer > read() throws IOException{
		
		HashMap< String, Integer > data = new HashMap< String, Integer >();
		header = buffer.readLine();
		
		if( !header.equals( "game_table_movement_cost\t1" ) )
			throw new IOException( "Invalid Header of TableDamage" );
		
		top = buffer.readLine().split( "\t" );
		while( buffer.ready() ){
			row = buffer.readLine().split( "\t" );
			for(int i = 1; i < top.length; i++){
				String id = top[i]+ " " +row[0];
				int damage = Integer.parseInt( row[i] );
				data.put( id, damage );
			}
		}
		return data;
	}
}
